//
//  SecondViewController.m
//  UI09_Homework
//
//  Created by dllo on 16/6/16.
//  Copyright © 2016年 司昌宝. All rights reserved.
//

#import "SecondViewController.h"
#import "secondScrollView.h"
@interface SecondViewController ()<UIScrollViewDelegate>

@property(nonatomic,retain)NSMutableArray *imageArray;

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    self.navigationItem.title = @"第二页";
    self.navigationController.automaticallyAdjustsScrollViewInsets = NO;
    self.navigationController.navigationBar.backgroundColor = [UIColor redColor];
    self.navigationController.navigationBar.translucent = NO;
    [self createScrollView];
}

-(void)createScrollView{
    self.imageArray = [NSMutableArray arrayWithCapacity:6];
    for (NSInteger i = 0;i < 6;i++){
        NSString *name = [NSString stringWithFormat:@"cat_%ld.jpg",i + 1];
        UIImage *image = [UIImage imageNamed:name];
        [self.imageArray addObject:image];
    }
    
    secondScrollView *scrollView = [[secondScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) withImageArray:self.imageArray];
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if(scrollView.contentOffset.x == 0){
        scrollView.contentOffset = CGPointMake((self.imageArray.count) * CGRectGetWidth(scrollView.bounds), 0);
    } else if (scrollView.contentOffset.x == (self.imageArray.count + 1) *CGRectGetWidth(self.view.bounds)){
        scrollView.contentOffset = CGPointMake(CGRectGetWidth(self.view.bounds), 0);
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
